//if (!console) {
if (!console || navigator.userAgent.toLowerCase().indexOf('safari') > 0) {
	var console = {
		// properties
		_container: null,
		_display: null,
		_initialized: false,
		
		// private methods
		init: function() {
			if (this._initialized) return;	
			
			if (!document.body) {
				setTimeout('console.init()',100);
				return;
			}
			
			this._container = document.createElement('div');
			this._container.style.position = 'fixed';
			this._container.style.bottom = '0';
			this._container.style.left = '0';
			this._container.style.width = '100px';
			this._container.style.font = '11px Arial';
			this._container.style.border = '1px solid #ccc';
			this._container.style.backgroundColor = '#ccc';
			this._container.style.MozOpacity = '0.9';
			
			document.body.appendChild(this._container);
			
			var title = document.createElement('div');
			title.innerHTML = 'Console';
			title.style.padding = '2px';
			title.style.cssFloat = title.style.styleFloat = 'left';
			this._container.appendChild(title);
			
			var buttons = document.createElement('div');
			buttons.style.padding = '2px';
			buttons.style.cssFloat = buttons.style.styleFloat = 'right';
			buttons.innerHTML = '<a href="javascript:console.clear();void(0);">clear</a> <a href="javascript:console.open();void(0);">open</a> <a href="javascript:console.close();void(0);">close</a>';
			this._container.appendChild(buttons);
										
			this._display = document.createElement('div');
			this._container.appendChild(this._display);
			this._display.style.clear = 'both';
			this._display.style.height = '200px';
			this._display.style.background = '#fff';
			this._display.style.fontFamily = 'Courier New, Courier';
			this._display.style.fontSize = '9pt';
			this._display.style.overflow = 'auto';
			
			this.updateSize();
		
			if (window.addEventListener) {
				window.addEventListener('resize', function() {console.updateSize();}, true);
			}  else if (window.attachEvent) {
				window.attachEvent('onresize', function() {console.updateSize();});
			}

			this._initialized = true;			
		},
		_scrollToBottom: function() {
			this._display.scrollTop = this._display.scrollHeight;
		},
		log: function() {
			if (!this._initialized) this.init();
			if (this._display == null) return;
			var line = document.createElement('div');
			line.style.borderBottom = '1px solid #ccc';
			line.style.padding = '1px';
			
			var s = '';
			for (var i=0; i<arguments.length; i++) {
				var arg = arguments[i];
				
				if (!arg) {
					s += 'undefined ';
					continue;
				}
				
				
				if (typeof(arg) == 'string') {
					s += '' + this.esc(arg) + ' ';
				} else if (typeof(arg) == 'number') {
					s += '' + arg + ' ';					
				} else if (arg.constructor && arg.constructor.toString().indexOf("Array") > -1) {
					s += '[' + arg + '] ';
				} else if (arg.constructor && arg.constructor.toString().indexOf("Date") > -1) {
					s += 'Date: ' + arg + ' ';					
				} else if (typeof(arg) == 'object') {
					s += 'Object: ';
					for (var prop in arg) 	
						if ( typeof( arg[prop] ) != 'function') {
							s += prop;
							try {
								s += '=' + arg[prop] + ', ';
							} catch (e) {}
						}
				} else {
					s += typeof(arg) + ' ' + arg + ' ';
				}
				
				//s += arg + ' ';
						
			}
			
			line.innerHTML = s;
			this._display.appendChild(line);
			this._scrollToBottom();
			this.show();
		},
		esc: function(s) {
			return s.replace(/>/g,'&gt;').replace(/</g,'&lt;');
		},
		clear: function() {
			while (this._display.childNodes.length > 0)
				this._display.removeChild(this._display.childNodes[this._display.childNodes.length-1]);
		},
		show: function() {			
			this._container.style.display = 'block';
		},
		hide: function() {
			this._container.style.display = 'none';
		},
		open: function() {
			this._display.style.display = 'block';
		},	
		close: function() {
			this._display.style.display = 'none';
		},				
		updateSize: function() {
			if (self.innerWidth)
			{
				frameWidth = self.innerWidth;
				frameHeight = self.innerHeight;
			}
			else if (document.documentElement && document.documentElement.clientWidth)
			{
				frameWidth = document.documentElement.clientWidth;
				frameHeight = document.documentElement.clientHeight;
			}
			else if (document.body)
			{
				frameWidth = document.body.clientWidth;
				frameHeight = document.body.clientHeight;
			}
			this._container.style.width = frameWidth + 'px';
		}
	};
	
	if (window.addEventListener) {
		window.addEventListener('load', function() {console.init();}, true);
	}  else if (window.attachEvent) {
		window.attachEvent('onload', function() {console.init();});
	}
}